﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Imagin.Controls.Common"
    xmlns:Common.Data.Converters="clr-namespace:Imagin.Common.Data.Converters;assembly=Imagin.Common"
    xmlns:System="clr-namespace:System;assembly=mscorlib">
    <Common.Data.Converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
    <Common.Data.Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

    <Style x:Key="{x:Type local:MaskedImage}" TargetType="{x:Type local:MaskedImage}">
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MaskedImage}">
                    <Border 
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        Padding="{TemplateBinding Padding}"
                        HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Rectangle 
                            Width="{TemplateBinding ImageWidth}" 
                            Height="{TemplateBinding ImageHeight}" 
                            Fill="{TemplateBinding ImageColor}" 
                            OpacityMask="{TemplateBinding ImageBrush}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type local:MaskedButton}" TargetType="{x:Type local:MaskedButton}">
        <Setter Property="ContentMargin" Value="5,0,0,0" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Width" Value="Auto" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="Margin" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MaskedButton}">
                    <ControlTemplate.Resources>
                        <Style 
                            x:Key="Style.MaskedButton.DropDownButton"
                            TargetType="{x:Type ContentControl}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ContentControl}">
                                        <local:MaskedImage
                                            x:Name="PART_Rectangle"
                                            Cursor="Hand"
                                            ImageColor="{TemplateBinding Foreground}"
                                            RenderTransformOrigin="0.5,0.5"
                                            Source="pack://application:,,,/Imagin.Controls.Common;component/Images/ArrowDownSmall.png">
                                            <local:MaskedImage.RenderTransform>
                                                <RotateTransform Angle="-90"/>
                                            </local:MaskedImage.RenderTransform>
                                        </local:MaskedImage>
                                        <ControlTemplate.Triggers>
                                            <DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType={x:Type local:MaskedButton}}}" Value="True">
                                                <DataTrigger.EnterActions>
                                                    <BeginStoryboard>
                                                        <Storyboard>
                                                            <DoubleAnimation 
                                                                Duration="0:0:0.25" 
                                                                Storyboard.TargetName="PART_Rectangle" 
                                                                Storyboard.TargetProperty="RenderTransform.Angle" 
                                                                From="-90" 
                                                                To="0"/>
                                                        </Storyboard>
                                                    </BeginStoryboard>
                                                </DataTrigger.EnterActions>
                                                <DataTrigger.ExitActions>
                                                    <BeginStoryboard>
                                                        <Storyboard>
                                                            <DoubleAnimation 
                                                                Duration="0:0:0.25" 
                                                                Storyboard.TargetName="PART_Rectangle" 
                                                                Storyboard.TargetProperty="RenderTransform.Angle" 
                                                                From="0" 
                                                                To="-90"/>
                                                        </Storyboard>
                                                    </BeginStoryboard>
                                                </DataTrigger.ExitActions>
                                                <Setter Property="Foreground" Value="{DynamicResource Brush.Image.Pressed}"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType={x:Type local:MaskedButton}}}" Value="False">
                                                <Setter Property="Foreground" Value="{DynamicResource Brush.Image}"/>
                                            </DataTrigger>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="Foreground" Value="{DynamicResource Brush.Image.MouseOver}"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ControlTemplate.Resources>
                    <Border  
                        BorderThickness="{TemplateBinding BorderThickness}" 
                        BorderBrush="{TemplateBinding BorderBrush}"  
                        Background="{TemplateBinding Background}"
                        Padding="{TemplateBinding Padding}">
                        <local:RippleDecorator
                            BorderBrush="{TemplateBinding ImageColor}"
                            IsRippleEnabled="{TemplateBinding IsRippleEnabled}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <local:MaskedImage
                                        x:Name="PART_Rectangle" 
                                        Source="{TemplateBinding Source}"
                                        ImageWidth="{TemplateBinding ImageWidth}" 
                                        ImageHeight="{TemplateBinding ImageHeight}"
                                        ImageColor="{TemplateBinding ImageColor}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Visibility="{TemplateBinding Source, Converter={StaticResource NullToVisibilityConverter}}"/>
                                <ContentPresenter 
                                    Grid.Column="1" 
                                    x:Name="PART_Content"
                                    Content="{TemplateBinding Content}" 
                                    Margin="{TemplateBinding ContentMargin}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding Content, Converter={StaticResource NullToVisibilityConverter}}"/>
                                <ContentControl 
                                    Grid.Column="2" 
                                    x:Name="PART_Dropdown"
                                    Style="{StaticResource Style.MaskedButton.DropDownButton}"
                                    ToolTip="{TemplateBinding DropDownButtonToolTip}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding DropDownButtonVisibility}"/>
                            </Grid>
                        </local:RippleDecorator>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type local:MaskedToggleButton}" TargetType="{x:Type local:MaskedToggleButton}">
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MaskedToggleButton}">
                    <Border  
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        BorderThickness="{TemplateBinding BorderThickness}" 
                        Background="{TemplateBinding Background}"
                        Padding="{TemplateBinding Padding}">
                        <local:RippleDecorator
                            BorderBrush="{TemplateBinding ImageColor}"
                            IsRippleEnabled="{TemplateBinding IsRippleEnabled}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <local:MaskedImage
                                    x:Name="PART_Rectangle" 
                                    Margin="0"
                                    Padding="0"
                                    Source="{TemplateBinding Source}"
                                    ImageWidth="{TemplateBinding ImageWidth}" 
                                    ImageHeight="{TemplateBinding ImageHeight}"
                                    ImageColor="{TemplateBinding ImageColor}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding Source, Converter={StaticResource NullToVisibilityConverter}}"/>
                                <ContentPresenter 
                                    Grid.Column="1" 
                                    x:Name="PART_Content"
                                    Content="{TemplateBinding Content}" 
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    Margin="{TemplateBinding ContentMargin}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding Content, Converter={StaticResource NullToVisibilityConverter}}"/>
                            </Grid>
                        </local:RippleDecorator>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type local:MaskedDropDownButton}" TargetType="{x:Type local:MaskedDropDownButton}">
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MaskedDropDownButton}">
                    <Border 
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        Padding="{TemplateBinding Padding}">
                        <local:RippleDecorator
                            BorderBrush="{TemplateBinding ImageColor}"
                            IsRippleEnabled="{TemplateBinding IsRippleEnabled}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <local:MaskedImage
                                    x:Name="PART_Rectangle" 
                                    Source="{TemplateBinding Source}"
                                    ImageWidth="{TemplateBinding ImageWidth}" 
                                    ImageHeight="{TemplateBinding ImageHeight}"
                                    ImageColor="{TemplateBinding ImageColor}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding Source, Converter={StaticResource NullToVisibilityConverter}}"/>
                                <ContentControl 
                                    Grid.Column="1" 
                                    x:Name="PART_Content"
                                    Content="{TemplateBinding Content}" 
                                    Margin="{TemplateBinding ContentMargin}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding Content, Converter={StaticResource NullToVisibilityConverter}}"/>
                            </Grid>
                        </local:RippleDecorator>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>